<html xmlns="http://www.w3.org/1999/xhtml"  
      xmlns:h="http://java.sun.com/jsf/html"  
      xmlns:f="http://java.sun.com/jsf/core"  
      xmlns:p="http://primefaces.org/ui"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:pe="http://primefaces.org/ui/extensions"> 

    <ui:composition template="../index.xhtml">
        <ui:define name="conteudo">
            <h:form style="text-align: left;">
                <h:outputText value="Emissão de Nota Fiscal Manualmente" style="font-size: 18px; color: red;"/>
            </h:form>
            <h:form>
                <p:growl id="msg"/>
                <p:accordionPanel id="AcordionPrinc">
                    <p:tab title="Empresa emitente (#{digitaNfeControler.nfe.empresa.razaoSocial})" id="tabEmpresa">

                        <p:selectOneMenu value="#{digitaNfeControler.nfe.empresa.id}" id="empresa" >  
                            <f:selectItems value="#{empresaControler.listEmpresa}" var="sb" itemValue="#{sb.id}" itemLabel="#{sb.razaoSocial}" /> 
                            <p:ajax event="change" update="AcordionPrinc" listener="#{digitaNfeControler.setaEmpresa()}"/>
                        </p:selectOneMenu>

                        <h:panelGrid columns="4" rendered="false">
                            <h:panelGrid columns="1">
                                <h:outputText value="Nome fantasia" style="font-weight: bold;"/>
                                <h:outputText value="#{digitaNfeControler.nfe.empresa.nomeFantasia}"/>

                                <h:outputText value="Nome fantasia" style="font-weight: bold;"/>
                                <h:outputText value="#{digitaNfeControler.nfe.empresa.nomeFantasia}"/>
                            </h:panelGrid>
                        </h:panelGrid>
                    </p:tab>
                    <p:tab title="Dados gerais">
                        <h:panelGrid columns="3" >
                            <h:panelGrid columns="1">
                                <h:outputText value="Número da NF-e: " />
                                <p:inputText value="#{digitaNfeControler.nfe.numero}"/>
                            </h:panelGrid>

                            <h:panelGrid columns="1">
                                <h:outputText value="Série: " />
                                <p:inputText value="#{digitaNfeControler.nfe.serie}"/>
                            </h:panelGrid>

                            <h:panelGrid columns="1">
                                <h:outputText value="Natureza da operação: " />
                                <p:selectOneMenu value="#{digitaNfeControler.nfe.naturezaOperacao}" id="cfop">  
                                    <f:selectItems value="#{cfopControler.listCfop}" var="cfop" itemValue="#{cfop.cfop}" itemLabel="#{cfop.cfop} - #{cfop.descricao}"/> 
                                </p:selectOneMenu>
                            </h:panelGrid>

                            <h:panelGrid columns="1">
                                <h:outputText value="Tipo de emissão: " />
                                <p:selectOneMenu value="#{digitaNfeControler.nfe.tipoEmissao}" style="width: 150px;">  
                                    <f:selectItem itemValue="1" itemLabel="Normal"/>
                                </p:selectOneMenu>
                            </h:panelGrid>

                            <h:panelGrid columns="1">
                                <h:outputText value="Tipo de operação: " />
                                <p:selectOneMenu value="#{digitaNfeControler.nfe.tipoOperacao}" style="width: 150px;">  
                                    <f:selectItem itemValue="1" itemLabel="Saida"/>
                                    <f:selectItem itemValue="2" itemLabel="Entrada"/>
                                </p:selectOneMenu>
                            </h:panelGrid>

                        </h:panelGrid>
                    </p:tab>
                    <!--*******************************************************************-->
                    <!--******************************CLIENTE******************************-->
                    <!--*******************************************************************-->
                    <p:tab title="Cliente" id="tabCliente">
                        <h:panelGrid columns="1">
                            <h:outputText value="Digite p/ Pesquisar"/>
                            <p:autoComplete id="acForcea" value="#{digitaNfeControler.txt2}" forceSelection="true" size="80"
                                            completeMethod="#{digitaNfeControler.completeCliente}" >
                                <p:ajax event="itemSelect" listener="#{digitaNfeControler.handleSelectCliente}" />
                                <p:ajax event="itemSelect" update="PanelDadosCliente" />
                            </p:autoComplete>
                        </h:panelGrid>
                        <h:panelGrid columns="4" id="PanelDadosCliente">
                            <h:panelGrid columns="1"  rendered="#{digitaNfeControler.nfe.cliente.tipoPessoa.toString().equalsIgnoreCase('J')}">
                                <h:outputText value="Razão social" style="font-weight: bold;" />
                                <h:outputText value="#{digitaNfeControler.nfe.cliente.nome}"/>
                            </h:panelGrid>

                            <h:panelGrid columns="1" rendered="#{digitaNfeControler.nfe.cliente.tipoPessoa.toString().equalsIgnoreCase('J')}">
                                <h:outputText value="Nome fantasia" style="font-weight: bold;"/>
                                <h:outputText value="#{digitaNfeControler.nfe.cliente.fantasia}"/>
                            </h:panelGrid>

                            <h:panelGrid columns="1" rendered="#{digitaNfeControler.nfe.cliente.tipoPessoa.toString().equalsIgnoreCase('F')}">
                                <h:outputText value="Nome " style="font-weight: bold;"/>
                                <h:outputText value="#{digitaNfeControler.nfe.cliente.nome}"/>
                            </h:panelGrid>

                            <h:panelGrid columns="1">
                                <h:outputText value="CNPJ/CPF" style="font-weight: bold;"/>
                                <h:outputText value="#{digitaNfeControler.nfe.cliente.cpfCnpj}"/>
                            </h:panelGrid>

                            <h:panelGrid columns="1" rendered="#{digitaNfeControler.nfe.cliente.tipoPessoa.toString().equalsIgnoreCase('J')}">
                                <h:outputText value="Inscrição estadual" style="font-weight: bold;"/>
                                <h:outputText value="#{digitaNfeControler.nfe.cliente.inscricaoEstadual}"/>
                            </h:panelGrid>

                            <h:panelGrid columns="1" rendered="#{digitaNfeControler.nfe.cliente.tipoPessoa.toString().equalsIgnoreCase('F')}">
                                <h:outputText value="RG" style="font-weight: bold;"/>
                                <h:outputText value="#{digitaNfeControler.nfe.cliente.rg}"/>
                            </h:panelGrid>

                            <h:panelGrid columns="1">
                                <h:outputText value="Telefone 1" style="font-weight: bold;"/>
                                <h:outputText value="#{digitaNfeControler.nfe.cliente.fone1}"/>
                            </h:panelGrid>

                            <h:panelGrid columns="1">
                                <h:outputText value="Telefone 2" style="font-weight: bold;"/>
                                <h:outputText value="#{digitaNfeControler.nfe.cliente.fone2}"/>
                            </h:panelGrid>

                            <h:panelGrid columns="1">
                                <h:outputText value="Celular" style="font-weight: bold;"/>
                                <h:outputText value="#{digitaNfeControler.nfe.cliente.celular}"/>
                            </h:panelGrid>

                            <h:panelGrid columns="1">
                                <h:outputText value="Cep" style="font-weight: bold;"/>
                                <h:outputText value="#{digitaNfeControler.nfe.cliente.cep}"/>
                            </h:panelGrid>

                            <h:panelGrid columns="1">
                                <h:outputText value="Logradouro" style="font-weight: bold;"/>
                                <h:outputText value="#{digitaNfeControler.nfe.cliente.logradouro}, #{digitaNfeControler.nfe.cliente.numero}"/>
                            </h:panelGrid>

                            <h:panelGrid columns="1">
                                <h:outputText value="Bairro" style="font-weight: bold;"/>
                                <h:outputText value="#{digitaNfeControler.nfe.cliente.bairro}"/>
                            </h:panelGrid>

                            <h:panelGrid columns="1">
                                <h:outputText value="Cidade" style="font-weight: bold;"/>
                                <h:outputText value="#{digitaNfeControler.nfe.cliente.idCidade.cidade} - #{digitaNfeControler.nfe.cliente.idCidade.estado}"/>
                            </h:panelGrid>

                        </h:panelGrid>
                    </p:tab>
                    <!--*******************************************************************-->
                    <!--******************************PRODUTO******************************-->
                    <!--*******************************************************************-->
                    <p:tab title="Produtos" id="panelProdutos">
                        <h:panelGrid columns="5" id="PanelProd">
                            <h:panelGrid columns="1">
                                Código:
                                <p:inputText value="#{digitaNfeControler.produto.gtin}" maxlength="13" size="15">
                                    <p:ajax event="blur" listener="#{digitaNfeControler.retornProdutoPorCodigo()}" update="PanelProd"/>
                                </p:inputText>
                            </h:panelGrid>
                            <h:panelGrid columns="1">
                                Descrição:
                                <p:autoComplete id="acForce" value="#{digitaNfeControler.txt1}" forceSelection="true"
                                                completeMethod="#{digitaNfeControler.complete}" size="80">
                                    <p:ajax event="itemSelect" listener="#{digitaNfeControler.handleSelect}" />
                                    <p:ajax event="itemSelect" update="PanelProd" />
                                </p:autoComplete>
                            </h:panelGrid>
                            <h:panelGrid columns="1">
                                Vlr.Unitário:
                                <p:inputText value="#{digitaNfeControler.produto.valorVenda}" size="8" disabled="true"/> 
                            </h:panelGrid>
                            <h:panelGrid columns="1">
                                Quantidade:
                                <p:inputText value="#{digitaNfeControler.nfeDetalhe.quantidadeComercial}" maxlength="5" size="8"/> 
                            </h:panelGrid>
                            <h:panelGrid columns="1">
                                <h:outputText value="." style="color: white;"/>
                                <p:commandButton value="Ok" action="#{digitaNfeControler.adicionaItem()}" update="@form"/> 
                            </h:panelGrid>
                        </h:panelGrid>
                        <ui:include src="_listProdutos.xhtml"/>
                    </p:tab>

                    <p:tab title="Totalizadores" id="Totalizador">
                        <h:panelGrid columns="5">
                            <h:panelGrid columns="1">
                                Total BC ICMS
                                <p:inputText value="#{digitaNfeControler.nfe.baseCalculoIcms}" maxlength="5"/>
                            </h:panelGrid>

                            <h:panelGrid columns="1">
                                Total ICMS
                                <p:inputText value="#{digitaNfeControler.nfe.valorIcms}" maxlength="5"/>
                            </h:panelGrid>

                            <h:panelGrid columns="1">
                                Total BC ICMS ST
                                <p:inputText value="#{digitaNfeControler.nfe.baseCalculoIcmsSt}" maxlength="5"/> 
                            </h:panelGrid>

                            <h:panelGrid columns="1">
                                Total ICMS ST
                                <p:inputText value="#{digitaNfeControler.nfe.valorIcmsSt}" maxlength="5"/> 
                            </h:panelGrid>

                            <h:panelGrid columns="1">
                                Total bruto dos produtos
                                <p:inputText value="#{digitaNfeControler.nfe.valorTotal}" maxlength="5"/> 
                            </h:panelGrid>

                            <h:panelGrid columns="1">
                                Total de frete
                                <p:inputText value="#{digitaNfeControler.nfe.valorFrete}" maxlength="5"/> 
                            </h:panelGrid>

                            <h:panelGrid columns="1">
                                Total de seguro
                                <p:inputText value="#{digitaNfeControler.nfe.valorSeguro}" maxlength="5"/> 
                            </h:panelGrid>

                            <h:panelGrid columns="1">
                                Total de desconto
                                <p:inputText value="#{digitaNfeControler.nfe.valorDesconto}" maxlength="5"/> 
                            </h:panelGrid>

                            <h:panelGrid columns="1">
                                Total de II
                                <p:inputText value="#{digitaNfeControler.nfeDetalhe.valorBcIi}" maxlength="5"/> 
                            </h:panelGrid>

                            <h:panelGrid columns="1">
                                Total de IPI
                                <p:inputText value="#{digitaNfeControler.nfe.valorIpi}" maxlength="5"/> 
                            </h:panelGrid>

                            <h:panelGrid columns="1">
                                Total de PIS
                                <p:inputText value="#{digitaNfeControler.nfe.valorPis}" maxlength="5"/> 
                            </h:panelGrid>

                            <h:panelGrid columns="1">
                                Total de PIS ST
                                <p:inputText value="#{digitaNfeControler.nfeDetalhe.ctsPis}" maxlength="5"/> 
                            </h:panelGrid>

                            <h:panelGrid columns="1">
                                Total de COFINS
                                <p:inputText value="#{digitaNfeControler.nfe.valorCofins}" maxlength="5"/> 
                            </h:panelGrid>

                            <h:panelGrid columns="1">
                                Total de COFINS ST
                                <p:inputText value="#{digitaNfeControler.nfeDetalhe.cstCofins}" maxlength="5"/> 
                            </h:panelGrid>

                            <h:panelGrid columns="1">
                                Total Outras Despesas
                                <p:inputText value="#{digitaNfeControler.nfe.valorDespesasAcessorias}" maxlength="5"/> 
                            </h:panelGrid>

                            <h:panelGrid columns="1">
                                TOTAL DA NF
                                <p:inputText value="#{digitaNfeControler.nfe.valorTotal}" maxlength="5"/> 
                            </h:panelGrid>
                        </h:panelGrid>
                        <p:commandButton value="Cancelar digitação" onclick="confirmationDigitacao.show();" />
                        <p:commandButton value="Gerar nota" action="#{digitaNfeControler.salvarNota()}" update="@form" onclick="statusDialog.show();" onsuccess="statusDialog.hide();"/>
                    </p:tab>
                </p:accordionPanel>
                <p:confirmDialog id="confirmDialog" message="Confirma cancelar a digitação da nota?" appendToBody="true"
                                 header="Atenção!!!" severity="alert" widgetVar="confirmationDigitacao" >  
                    <p:commandButton id="confirm" value="Sim" oncomplete="confirmationDigitacao.hide()"  
                                     actionListener="#{digitaNfeControler.inicializaObj()}" update="@form"/>  
                    <p:commandButton id="decline" value="Cancelar" onclick="confirmationDigitacao.hide()" type="button" />   
                </p:confirmDialog>
            </h:form>
        </ui:define>
    </ui:composition>
</html>